package bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Student implements BeanNameAware,
        BeanFactoryAware,
        ApplicationContextAware,
        InitializingBean,
        DisposableBean {

    private String name;
    private int age;
    private String gender="男";

    public Student() {
        System.out.println("bean的生命周期之实例化");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("bean的生命周期之name属性赋值");
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        System.out.println("bean的生命周期之age属性赋值");
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        System.out.println("bean的生命周期之gender属性赋值");
        this.gender = gender;
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("bean的生命周期之setBeanName");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("bean的生命周期之setBeanFactory");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("bean的生命周期之setApplicationContext");
    }

    //标准初始化
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("bean的生命周期之标准初始化");
    }

    //自定义初始化，在标准初始化之后执行，但不是必须存在
    public void myInit(){
        System.out.println("bean的生命周期之自定义初始化");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("bean的生命周期之标准销毁");
    }

    public void myDestroy(){
        System.out.println("bean的生命周期之自定义销毁");
    }
}
